//
//  ZJUserAccountTools.m
//  Weibo29
//
//  Created by 曾静 on 16/6/30.
//  Copyright © 2016年 qq. All rights reserved.
//

#import "ZJUserAccountTools.h"

@implementation ZJUserAccountTools



//差创建单例.实现整个函数的数据
 static ZJUserAccountTools *_instance;
+(instancetype)shareAccountTools{

    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        _instance = [[ZJUserAccountTools alloc]init];
        
        //每次程序再次启动的时候,创建单例,实现接档,将单例类的属性赋值
        _instance.userAccount = [_instance getUserAccount];
    });
    return _instance;
    
    
    
    
}



//实现保存用户的数据
-(BOOL)saveUserAccount:(ZJUserAccount *)userAccount{
    //因为但单例类只创建一次,以后就不会再创近建了,对象的属性只会还要使用,就在保存数据的瞬间往单例类的属性赋值就好了
    
    self.userAccount = userAccount;
    
    NSString *path = [[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject]stringByAppendingPathComponent:@"user.achiever"];
    
   return  [NSKeyedArchiver archiveRootObject:userAccount toFile:path];
    
}
//实现读取用户的数据

-(ZJUserAccount*)getUserAccount{
    
      NSString *path = [[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject]stringByAppendingPathComponent:@"user.achiever"];
    
    return [NSKeyedUnarchiver unarchiveObjectWithFile:path];
    
}
@end
